package com.wisdytech.linkdcs.tool.action;


import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.linkdcs.tool.model.TtEqTool;
import com.wisdytech.linkdcs.tool.service.IToolMaintainRecordService;
import com.wisdytech.linkdcs.tool.vo.ToolMaintainVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-11
 */
@Controller
@RequestMapping("/tool/maintainRecord")
public class ToolMaintainRecordAction {

    @Resource
    private IToolMaintainRecordService toolMaintainRecordService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
     * <p>Description: 工装校验记录查询</p>
     *
     * @param model model
     * @return String
     */
    @RequestMapping("/index")
    public String toolCheckIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "tool/toolMaintainRecord";
    }

    @RequestMapping(value = "/getToolMaintainRecordByFilter/get.mvc")
    @ResponseBody
    public StandardTableResult<TtEqTool> getToolMaintainRecordByFilter(String toolCode, String toolName, String toolModel, String toolType, String opCode, String maintainDateStart, String maintainDateEnd, Filter filter) {
        PageInfo<TtEqTool> page = this.toolMaintainRecordService.getToolMaintainRecordByFilter(toolCode, toolName, toolModel, toolType, opCode, maintainDateStart, maintainDateEnd, filter);
        return new StandardTableResult<>(page.getTotal(), page.getList());
    }

    @RequestMapping(value = "/getToolMaintainResult/get.mvc")
    @ResponseBody
    public StandardResult getToolMaintainResult(String pkId) {
        ToolMaintainVO vo = this.toolMaintainRecordService.getToolMaintainResult(pkId);
        return StandardResult.getSuccessResult(vo);
    }
}
